/*
 * SongInfoPanel.java
 *
 * Created on September 19, 2005, 3:04 PM
 */
package com.bff.slimserver.musicjukebox.ui;

import com.bff.bjj.ui.component.BJJPanel;
import java.util.Collection;
import org.bff.slimserver.events.PlaylistChangeEvent;
import org.bff.slimserver.events.SavedPlaylistChangeEvent;
import org.bff.slimserver.musicobjects.SlimAlbum;
import org.bff.slimserver.musicobjects.SlimArtist;
import org.bff.slimserver.musicobjects.SlimFolderObject;
import org.bff.slimserver.musicobjects.SlimGenre;
import org.bff.slimserver.musicobjects.SlimPlayableObject;
import org.bff.slimserver.musicobjects.SlimSong;
import org.bff.slimserver.musicobjects.SlimPodcastItem;

/**
 *
 * @author  Bill
 */
public class SongRetractInfoPanel
        extends BJJPanel {

    public SongRetractInfoPanel() {
        this(null);
    }

    public SongRetractInfoPanel(SlimPlayableObject object) {
        initComponents();
        setInfo(object, null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        lblMsgTop = new javax.swing.JLabel();
        lblMsgCenter = new javax.swing.JLabel();
        lblMsgBottom = new javax.swing.JLabel();

        setForeground(new java.awt.Color(102, 102, 102));
        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(java.awt.Color.lightGray);
        jPanel1.setLayout(new java.awt.GridBagLayout());

        lblMsgTop.setForeground(new java.awt.Color(0, 102, 255));
        lblMsgTop.setText("Text");
        jPanel1.add(lblMsgTop, new java.awt.GridBagConstraints());

        lblMsgCenter.setForeground(new java.awt.Color(0, 102, 255));
        lblMsgCenter.setText("Text");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanel1.add(lblMsgCenter, gridBagConstraints);

        lblMsgBottom.setForeground(new java.awt.Color(0, 102, 255));
        lblMsgBottom.setText("Text");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        jPanel1.add(lblMsgBottom, gridBagConstraints);

        add(jPanel1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblMsgBottom;
    private javax.swing.JLabel lblMsgCenter;
    private javax.swing.JLabel lblMsgTop;
    // End of variables declaration//GEN-END:variables

    /**
     * Pass null to remove all info
     * @param song
     */
    public void setInfo(SlimPlayableObject object, PlaylistChangeEvent event) {

        try {
            if (object != null) {
                if (object instanceof SlimSong) {
                    lblMsgTop.setText("Song");
                } else if (object instanceof SlimAlbum) {
                    lblMsgTop.setText("Album");
                } else if (object instanceof SlimArtist) {
                    lblMsgTop.setText("Artist");
                } else if (object instanceof SlimGenre) {
                    lblMsgTop.setText("Genre");
                } else if (object instanceof SlimPodcastItem) {
                    lblMsgTop.setText("Podcast");
                } else if (object instanceof SlimFolderObject) {
                    switch (((SlimFolderObject) object).getObjectType()) {
                        case FOLDER:
                            lblMsgTop.setText("Folder");
                            break;
                        case TRACK:
                            lblMsgTop.setText("Track");
                            break;
                        case PLAYLIST:
                            lblMsgTop.setText("Playlist");
                            break;
                        default:
                            lblMsgTop.setText("Folder");
                            break;
                    }
                } else {
                    lblMsgTop.setText("Item");
                }

                if (object.getName().length() > 40) {
                    lblMsgCenter.setText(" " + object.getName().substring(0, 40) + "...");
                } else {
                    lblMsgCenter.setText(" " + object.getName() + " ");
                }

                if (event != null) {
                    switch (event.getId()) {
                        case PlaylistChangeEvent.ITEM_ADDED:
                            lblMsgBottom.setText("added");
                            break;
                        case PlaylistChangeEvent.ITEM_INSERTED:
                            lblMsgBottom.setText("inserted");
                            break;
                        case PlaylistChangeEvent.ITEM_LOADED:
                            lblMsgBottom.setText("loaded");
                            break;
                        default:
                            lblMsgBottom.setText("added");
                            break;
                    }
                }

            }
        } catch (NullPointerException npe) {
            //dont give a shit
            npe.printStackTrace();
        }
    }

    /**
     * Pass null to remove all info
     * @param song
     */
    public void setSavedPlaylistInfo(SavedPlaylistChangeEvent event) {

        try {
            lblMsgTop.setText("Item");
            lblMsgCenter.setText("added to playlist");
            if (event.getNewPlaylist().getName().length() > 40) {
                lblMsgBottom.setText(" " + event.getNewPlaylist().getName().substring(0, 40) + "...");
            } else {
                lblMsgBottom.setText(" " + event.getNewPlaylist().getName() + " ");
            }
        } catch (NullPointerException npe) {
            lblMsgBottom.setText("");
            //dont give a shit
            npe.printStackTrace();
        }
    }

    public void setFavoriteInfo(String title) {
        lblMsgTop.setText("Favorite");
        if (title.length() > 40) {
            lblMsgCenter.setText(" " + title.substring(0, 40) + "...");
        } else {
            lblMsgCenter.setText(" " + title + " ");
        }
        lblMsgBottom.setText("added");
    }

    public void setYearInfo(String year) {
        lblMsgTop.setText("Year");
        lblMsgCenter.setText(year);
        lblMsgBottom.setText("added");
    }

    void setInfo(Collection<SlimPlayableObject> slimObjects) {
        lblMsgTop.setText(Integer.toString(slimObjects.size()));
        lblMsgCenter.setText("items");
        lblMsgBottom.setText("added");
    }
}
